import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _class;

import React from 'react';
import { Table, Popconfirm } from 'antd';
import { Bind } from 'lodash-decorators';
import { Button as ButtonPermission } from 'components/Permission';
import intl from 'utils/intl';
import { tableScrollWidth } from 'utils/utils';
import { yesOrNoRender, operatorRender } from 'utils/renderer';
var StorageList = (_dec = Bind(), _dec2 = Bind(), (_class = /*#__PURE__*/function (_React$Component) {
  _inherits(StorageList, _React$Component);

  var _super = _createSuper(StorageList);

  function StorageList() {
    _classCallCheck(this, StorageList);

    return _super.apply(this, arguments);
  }

  _createClass(StorageList, [{
    key: "handleEdit",
    value: function handleEdit(record) {
      var _this$props$onEdit = this.props.onEdit,
          onEdit = _this$props$onEdit === void 0 ? function (e) {
        return e;
      } : _this$props$onEdit;
      onEdit(record);
    }
  }, {
    key: "handleDelete",
    value: function handleDelete(record) {
      var _this$props$onDelete = this.props.onDelete,
          onDelete = _this$props$onDelete === void 0 ? function (e) {
        return e;
      } : _this$props$onDelete;
      onDelete(record);
    }
  }, {
    key: "render",
    value: function render() {
      var _this = this;

      var _this$props = this.props,
          _this$props$type = _this$props.type,
          type = _this$props$type === void 0 ? '1' : _this$props$type,
          path = _this$props.path,
          _this$props$loading = _this$props.loading,
          loading = _this$props$loading === void 0 ? false : _this$props$loading,
          _this$props$storageDa = _this$props.storageDataList,
          storageDataList = _this$props$storageDa === void 0 ? [] : _this$props$storageDa,
          _this$props$serverPro = _this$props.serverProviderList,
          serverProviderList = _this$props$serverPro === void 0 ? [] : _this$props$serverPro;
      var columns = [{
        title: intl.get('cfile.storage.model.storage.storageCode').d('存储编码'),
        dataIndex: 'storageCode',
        width: 150
      }, {
        title: intl.get('cfile.storage.model.storage.prefixStrategy').d('文件名前缀策略'),
        dataIndex: 'prefixStrategyMeaning',
        width: 150
      }, type !== '11' && {
        title: ['2', '3', '4', '6'].includes(type) ? intl.get('cfile.storage.model.storage.Domain2').d('代理地址') : intl.get('cfile.storage.model.storage.Domain').d('域名(Domain)'),
        dataIndex: 'domain',
        width: 200
      }, {
        title: type === '6' ? intl.get('cfile.storage.model.storage.storageRoute').d('存储路径') : type === '11' ? intl.get('cfile.storage.model.storage.endPointMeaning').d('区域') : intl.get('cfile.storage.model.storage.EndPoint').d('EndPoint'),
        dataIndex: type === '11' ? 'endPointMeaning' : 'endPoint'
      }, type !== '6' && {
        title: intl.get('cfile.storage.model.storage.AccessKeyId').d('AccessKeyId'),
        dataIndex: 'accessKeyId'
      }, type === '4' && {
        title: intl.get('cfile.storage.model.storage.AppId').d('AppId'),
        dataIndex: '',
        width: 200
      }, ['2', '4', '7', '8', '12'].includes(type) && {
        title: intl.get('cfile.storage.model.storage.region').d('Bucket所属地区'),
        dataIndex: 'region',
        width: 200
      }, type !== '6' && {
        title: intl.get('cfile.storage.model.storage.accessControl').d('bucket权限控制'),
        dataIndex: 'accessControl',
        width: 200,
        render: function render(value) {
          var types = {};
          serverProviderList.forEach(function (item) {
            if (item.value === type) {
              if (item.children) {
                types = item.children.find(function (children) {
                  return value === children.value;
                }) || {};
              }
            }
          });
          return types.meaning;
        }
      }, type !== '6' && {
        title: intl.get('cfile.storage.model.storage.prefix').d('bucket前缀'),
        dataIndex: 'bucketPrefix',
        width: 200
      }, {
        title: intl.get('cfile.storage.model.storage.defaultFlag').d('默认'),
        dataIndex: 'defaultFlag',
        width: 100,
        render: yesOrNoRender
      }, {
        title: intl.get('cpaas.common.button.action').d('操作'),
        dataIndex: 'action',
        fixed: 'right',
        width: 120,
        render: function render(_, record) {
          var operators = [];
          operators.push({
            key: 'edit',
            ele: /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.edit"),
                type: 'button',
                meaning: '文件存储配置-编辑'
              }],
              onClick: function onClick() {
                return _this.handleEdit(record);
              }
            }, intl.get('cpaas.common.button.edit').d('编辑')),
            len: 2,
            title: intl.get('cpaas.common.button.edit').d('编辑')
          }, {
            key: 'delete',
            ele: /*#__PURE__*/React.createElement(Popconfirm, {
              title: intl.get('cpaas.common.message.confirm.delete').d('是否删除此条记录？'),
              onConfirm: function onConfirm() {
                return _this.handleDelete(record);
              }
            }, /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.delete"),
                type: 'button',
                meaning: '文件存储配置-删除'
              }]
            }, intl.get('cpaas.common.button.delete').d('删除'))),
            len: 2,
            title: intl.get('cpaas.common.button.delete').d('删除')
          });
          return operatorRender(operators, record, {
            limit: 3
          });
        }
      }].filter(Boolean);
      return /*#__PURE__*/React.createElement(Table, {
        bordered: true,
        scroll: {
          x: tableScrollWidth(columns, 200)
        },
        rowKey: "storageConfigId",
        columns: columns,
        loading: loading,
        dataSource: storageDataList,
        pagination: false
      });
    }
  }]);

  return StorageList;
}(React.Component), (_applyDecoratedDescriptor(_class.prototype, "handleEdit", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "handleEdit"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleDelete", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "handleDelete"), _class.prototype)), _class));
export { StorageList as default };